﻿using DFGK_WMS.IRepository;
using DFGK_WMS.Model.DTO;
using DFGK_WMS.Model.Enum;
using DFGK_WMS.Model.Models;
using DFGK_WMS.WebAPI.Controllers.Result;
using Dm.Config;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NPOI.HSSF.UserModel;
using NPOI.SS.Formula.Functions;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System.Security.Claims;

namespace DFGK_WMS.WebAPI.Controllers.基础数据
{
    /// <summary>
    /// 仓位管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TCellController : ControllerBase
    {
        private readonly ILogRepository logRepository;
        public TCellController(ITCellRepository tCellRepository, ILogRepository logRepository)
        {
            TCellRepository = tCellRepository;
            this.logRepository = logRepository;
        }

        public ITCellRepository TCellRepository { get; }
        /// <summary>
        /// 添加仓位
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddTcell(TCellDto obj)
        {

            string message = "";
            ApiResult apiresult = new ApiResult();
            bool IsOK = TCellRepository.AddTcell(obj, out message);
            if (IsOK)
            {
                string uname = HttpContext.User.FindFirstValue("UserName");
                string runame = HttpContext.User.FindFirstValue("RealName");
                int uid = Convert.ToInt32(HttpContext.User.FindFirstValue("Id"));
                string? ip = HttpContext.Connection.RemoteIpAddress?.ToString();
                TLog logg = new TLog();
                logg.LogType = 1;
                logg.ActionType = 4;
                logg.ModuleName = "基础数据";
                logg.UserName = uname;
                logg.RealName = runame;
                logg.UserId = uid;
                logg.Description = uname + "创建了仓位" + obj.Name;
                //获取前端IP地址
                logg.Ipaddress = ip;

                logRepository.AddTLod(logg);
                apiresult.code = "200";
                apiresult.message = "添加成功!";
                apiresult.data = true;
                return Ok(apiresult);
            }
            apiresult.code = "500";
            apiresult.message = "添加失败！" + message;
            apiresult.data = true;
            return Ok(apiresult);
        }
        /// <summary>
        /// 修改仓位
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult UpdateTcell(TCellDto obj)
        {
            if (obj.Id <= 0)
            {
                return Ok(BaseResult.Result("400", "Id有误！"));
            }
            if (string.IsNullOrEmpty(obj.Code))
            {
                return Ok(BaseResult.Result("400", "必填项不能为空！"));
            }
            string message = "";
            ApiResult apiresult = new ApiResult();
            bool IsOK = TCellRepository.UpdateTcell(obj, out message);
            if (IsOK)
            {
                string uname = HttpContext.User.FindFirstValue("UserName");
                string runame = HttpContext.User.FindFirstValue("RealName");
                int uid = Convert.ToInt32(HttpContext.User.FindFirstValue("Id"));
                string? ip = HttpContext.Connection.RemoteIpAddress?.ToString();
                TLog logg = new TLog();
                logg.LogType = 1;
                logg.ActionType = 6;
                logg.ModuleName = "基础数据";
                logg.UserName = uname;
                logg.RealName = runame;
                logg.UserId = uid;
                logg.Description = uname + "修改了仓位" + obj.Name;
                //获取前端IP地址
                logg.Ipaddress = ip;

                logRepository.AddTLod(logg);
                apiresult.code = "200";
                apiresult.message = "修改成功！";
                apiresult.data = true;
                return Ok(apiresult);
            }
            apiresult.code = "500";
            apiresult.message = "修改失败！" + message;
            apiresult.data = true;
            return Ok(apiresult);
        }
        /// <summary>
        /// 删除仓位
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        [HttpDelete]
        public IActionResult DelTcell(int uid)
        {
            if (uid <= 0)
            {
                return Ok(BaseResult.Result("400", "Id有误！"));
            }
            ApiResult apiresult = new ApiResult();
            bool IsOK = TCellRepository.DelTcell(uid);
            if (IsOK)
            {
                string uname = HttpContext.User.FindFirstValue("UserName");
                string runame = HttpContext.User.FindFirstValue("RealName");
                int rid = Convert.ToInt32(HttpContext.User.FindFirstValue("Id"));
                string? ip = HttpContext.Connection.RemoteIpAddress?.ToString();
                TLog logg = new TLog();
                logg.LogType = 1;
                logg.ActionType = 5;
                logg.ModuleName = "基础数据";
                logg.UserName = uname;
                logg.RealName = runame;
                logg.UserId = rid;
                logg.Description = uname + "删除了仓位";
                //获取前端IP地址
                logg.Ipaddress = ip;

                logRepository.AddTLod(logg);
                apiresult.code = "200";
                apiresult.message = "删除成功!";
                apiresult.data = true;
                return Ok(apiresult);
            }
            apiresult.code = "500";
            apiresult.message = "删除失败!";
            apiresult.data = true;
            return Ok(apiresult);
        }
        /// <summary>
        /// 批量删除仓位
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        [HttpDelete]
        public IActionResult DelTcellList(int[] uidList)
        {
            if (uidList.Length <= 0)
            {
                return Ok(BaseResult.Result("400", "Id有误！"));
            }
            var daRes = true;
            ApiResult apiresult = new ApiResult();
            foreach (var uid in uidList)
            {
                bool IsOK = TCellRepository.DelTcell(uid);
                string uname = HttpContext.User.FindFirstValue("UserName");
                string runame = HttpContext.User.FindFirstValue("RealName");
                int rid = Convert.ToInt32(HttpContext.User.FindFirstValue("Id"));
                string? ip = HttpContext.Connection.RemoteIpAddress?.ToString();
                TLog logg = new TLog();
                logg.LogType = 1;
                logg.ActionType = 5;
                logg.ModuleName = "基础数据";
                logg.UserName = uname;
                logg.RealName = runame;
                logg.UserId = rid;
                logg.Description = IsOK ? uname + "删除了仓位" : uname + "删除仓位失败";
                //获取前端IP地址
                logg.Ipaddress = ip;
                logRepository.AddTLod(logg);
                if (!IsOK)
                {
                    daRes = false;
                    break;
                }
            }

            if (daRes)
            {
                apiresult.code = "200";
                apiresult.message = "删除成功!";
                apiresult.data = true;
                return Ok(apiresult);
            }
            apiresult.code = "500";
            apiresult.message = "删除失败!";
            apiresult.data = true;
            return Ok(apiresult);
        }
        /// <summary>
        /// 根据id获取信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetTcellById(int id)
        {
            if (id <= 0)
            {
                return Ok(BaseResult.Result("400", "Id有误！"));
            }
            var res = TCellRepository.GetTcellById(id);
            ApiResult apiresult = new ApiResult();
            if (res != null)
            {
                apiresult.code = "200";
                apiresult.message = "获取成功!";
                apiresult.data = res;
                return Ok(apiresult);
            }
            apiresult.code = "500";
            apiresult.message = "获取失败!";
            apiresult.data = true;
            return Ok(apiresult);
        }
        /// <summary>
        /// 获取库房(仓库)信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetTwarehouseList()
        {
            var res = TCellRepository.GetTwarehouseList();
            ApiResult apiresult = new ApiResult();
            if (res != null)
            {
                apiresult.code = "200";
                apiresult.message = "获取成功!";
                apiresult.data = res;
                return Ok(apiresult);
            }
            apiresult.code = "500";
            apiresult.message = "获取失败!";
            apiresult.data = true;
            return Ok(apiresult);
        }
        /// <summary>
        /// 获取库区信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetAreaList()
        {
            var res = TCellRepository.GetAreaList();
            ApiResult apiresult = new ApiResult();
            if (res != null)
            {
                apiresult.code = "200";
                apiresult.message = "获取成功!";
                apiresult.data = res;
                return Ok(apiresult);
            }
            apiresult.code = "500";
            apiresult.message = "获取失败!";
            apiresult.data = true;
            return Ok(apiresult);
        }

        /// <summary>
        /// 仓位左侧树形显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetMenuitemList()
        {
            var mlist = TCellRepository.GetMenuitem();

            if (mlist != null)
            {
                return Ok(BaseResult.Result(mlist, "获取成功！"));
            }

            return Ok(BaseResult.Result(null, "获取失败！"));
        }

        #region   通过排的方式获取仓位相关信息
        /// <summary>
        /// 获取仓位树形父子菜单列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetVitualCellMenuList()
        {
            try
            {
                return Ok(BaseResult.Result(TCellRepository.GetRowMenuItem(), "获取成功！"));
            }
            catch (Exception ex)
            {

                return Ok(BaseResult.Result(code: "500", "获取失败！" + ex.Message));
            }


        }

        /// <summary>
        /// 获取每排的仓位信息（排属于货架）
        /// </summary>
        /// <param name="wId">仓库id</param>
        /// <param name="aId">区域id</param>
        /// <param name="rId">排id</param>
        /// <param name="logicalPartCode">逻辑分区</param>
        /// <param name="fullStatus">是否满仓</param>
        /// <param name="status">仓位状态</param>
        /// <param name="cname">仓位名称</param>
        /// <param name="ccode">仓位编码</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">页容量</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetCellByMenuId(int rId, int aId, int wId, string? logicalPartCode = "", int fullStatus = 3, int status = 8, string? cname = "", string? ccode = "", int pageIndex = 1, int pageSize = 100)
        {

            try
            {
                var cellQueryble = TCellRepository.GetAll()

               ;

                if (wId != 0)
                {
                    cellQueryble = cellQueryble.Where(it => it.WhId == wId);
                }
                if (aId != 0)
                {
                    cellQueryble = cellQueryble.Where(it => it.AreaId == aId);
                }
                if (rId != 0)
                {
                    cellQueryble = cellQueryble.Where(it => it.ActualLine == rId);
                }


                //逻辑分区
                if (!string.IsNullOrEmpty(logicalPartCode))
                {
                    cellQueryble = cellQueryble.Where(x => x.LogicalPartCode == logicalPartCode);
                }
                //仓位状态
                if (fullStatus < 3)
                {
                    cellQueryble = cellQueryble.Where(x => x.FullStatus == fullStatus);
                }
                //状态
                if (status < 8)
                {
                    cellQueryble = cellQueryble.Where(x => x.Status == status);
                }
                //仓位名称
                if (!string.IsNullOrEmpty(cname))
                {
                    cellQueryble = cellQueryble.Where(x => x.Name.Contains(cname));
                }
                //实际仓位编码
                if (!string.IsNullOrEmpty(ccode))
                {
                    if (ccode.Length != 8)
                    {
                        return Ok(BaseResult.Result(code: "500", "仓位编码输入有误"));
                    }
                    // cellQueryble = cellQueryble.Where(x => x.ActualCellCode.Contains(ccode));
                }
                int toalCount = 0;
                toalCount = cellQueryble.Count();

                var result = cellQueryble.Skip(pageIndex)
                    .Take(pageSize)

                    .OrderBy(x => x.LineNo)

                    .ThenBy(x => x.ColumnNo)
                    .ThenBy(x => x.LayerNo)
                    .ToList();

                return Ok(BaseResult.Result(result, "200", toalCount));

            }
            catch (Exception ex)
            {

                return Ok(BaseResult.Result(code: "500", "获取失败！" + ex.Message));
            }


        }


        #endregion


        /// <summary>
        /// 批量设置
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult UpdateSetUp(Tcellll obj)
        {
            ApiResult apiresult = new ApiResult();
            bool IsOK = TCellRepository.UpdateSetUp(obj);
            if (IsOK)
            {
                apiresult.code = "200";
                apiresult.message = "修改成功!";
                apiresult.data = true;
                return Ok(apiresult);
            }
            apiresult.code = "500";
            apiresult.message = "修改失败!";
            apiresult.data = true;
            return Ok(apiresult);
        }
        /// <summary>
        /// 批量生成仓位
        /// </summary>
        /// <param name="cellCreateBodyDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult BatchCreateCell(CellCreateBodyDTO cellCreateBodyDTO)
        {
            if (cellCreateBodyDTO.WhId.GetValueOrDefault() <= 0 || cellCreateBodyDTO.AreaId.GetValueOrDefault() <= 0 || cellCreateBodyDTO.ShelfIds == null || cellCreateBodyDTO.ShelfIds.Count <= 0)
            {
                return Ok(BaseResult.Result(false, "未选择库房或库区或货架", "500"));
            }
            if (cellCreateBodyDTO.MaxLayer <= 0)
            {
                return Ok(BaseResult.Result(false, "最大层数未设置", "500"));
            }
            if (cellCreateBodyDTO.MaxColumn <= 0)
            {
                return Ok(BaseResult.Result(false, "最大列数未设置", "500"));
            }
            string message = "";
            var isOk = TCellRepository.BatchCreateCell(cellCreateBodyDTO, out message);
            if (isOk)
            {
                return Ok(BaseResult.Result(true, "批量添加成功！", "200"));
            }
            return Ok(BaseResult.Result(false, message, "500"));
        }

        /// <summary>
        /// 枚举业务类型
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetEmBusinessType()
        {
            var list = BaseEnum.GetCodeRulesList<EmBusinessType>();

            return Ok(list);
        }

        /// <summary>
        /// 枚举仓位状态
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetEmCellStatus()
        {
            var list = BaseEnum.GetCodeRulesList<EmCellStatus>();

            return Ok(list);
        }

        /// <summary>
        /// 枚举仓位类型
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetEmCellType()
        {
            var list = BaseEnum.GetCodeRulesList<EmCellType>();

            return Ok(list);
        }

        /// <summary>
        /// 枚举高度类型
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetEmHeightType()
        {
            var list = BaseEnum.GetCodeRulesList<EmHeightType>();

            return Ok(list);
        }

        /// <summary>
        /// 库房库区货架
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetWarAreaShellList()
        {
            var list = TCellRepository.GetWarAreaShellList();

            if (list != null)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200", 0));
            }
            return Ok(BaseResult.Result(null, "查询失败！", "500", 0));
        }

        /// <summary>
        /// 列表显示
        /// </summary>
        /// <param name="logicalPartCode"></param>
        /// <param name="fullStatus"></param>
        /// <param name="status"></param>
        /// <param name="cname"></param>
        /// <param name="whid"></param>
        /// <param name="areid"></param>
        /// <param name="sheid"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetCellList(string? logicalPartCode = "", int fullStatus = 3, int status = 8, string? cname = "", int whid = 0, int areid = 0, int sheid = 0, int pageIndex = 1, int pageSize = 10)
        {
            if (pageIndex <= 0 || pageSize <= 0)
            {
                BaseResult.Result("400", "分页条件有误！");
            }
            int totalCount;
            var list = TCellRepository.GetCellList(logicalPartCode, fullStatus, status, cname, whid, areid, sheid, pageIndex, pageSize, out totalCount);

            if (list != null)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200", totalCount));
            }
            return Ok(BaseResult.Result(null, "查询失败！", "500", 0));
        }

        #region 仓位直观图  

        /// <summary>
        /// 获取仓位层数
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetCellLayer()
        {
            try
            {
                return Ok(BaseResult.Result(TCellRepository.GetCellLayer(), "200"));
            }
            catch (Exception ex)
            {

                return Ok(BaseResult.Result(message: ex.Message, code: "500"));
            }
        }

        /// <summary>
        /// 根据层号获取每层仓位
        /// </summary>
        /// <param name="layerId"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetCellByLayerId(int layerId)
        {
            if (layerId == 0)
            {
                return Ok(BaseResult.Result(message: "Id不能为空", code: "500"));
            }
            try
            {
                return Ok(BaseResult.Result(TCellRepository.GetCellByLayer(layerId), "200"));
            }
            catch (Exception ex)
            {

                return Ok(BaseResult.Result(message: "程序异常" + ex.Message, code: "500"));
            }
        }

        /// <summary>
        /// 根据仓位编码获取库存
        /// </summary>
        /// <param name="cellId"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetInventoryByCell(int cellId)
        {
            if (cellId == 0)
            {
                return Ok(BaseResult.Result(message: "参数错误", code: "500"));
            }
            try
            {
                return Ok(BaseResult.Result(TCellRepository.GetInventoryByCell(cellId), "200"));
            }
            catch (Exception ex)
            {

                return Ok(BaseResult.Result(message: "程序异常" + ex.Message, code: "500"));
            }


        }

        /// <summary>
        /// 通过仓位Id获取仓位信息
        /// </summary>
        /// <param name="cellId"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetCellById(int cellId) 
        {
            if (cellId == 0)
            {
                return Ok(BaseResult.Result(message: "参数错误", code: "500"));
            }
            try
            {
                return Ok(BaseResult.Result(TCellRepository.GetCellById(cellId), "200"));
            }
            catch (Exception ex)
            {

                return Ok(BaseResult.Result(message: "程序异常" + ex.Message, code: "500"));
            }

        }


        #endregion


        /// <summary>
        /// file
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult UploadUserInfo(IFormFile file)
        {
            try
            {
                // 检查文件是否为空
                if (file == null || file.Length == 0)
                {
                    return Ok(BaseResult.Result("400", "没有选择文件或文件为空"));
                }
                string message = "";
                var postFile = Request.Form.Files[0];
                string extName = Path.GetExtension(postFile.FileName);
                if (!new string[] { ".xls", ".xlsx" }.Contains(extName))
                {
                    return Ok(BaseResult.Result("400", "必须是Excel文件"));
                }
                string uname = HttpContext.User.FindFirstValue("UserName");
                int uid = Convert.ToInt32(HttpContext.User.FindFirstValue("Id"));
                MemoryStream ms = new MemoryStream();
                postFile.CopyTo(ms);
                ms.Position = 0;
                IWorkbook wb = null;
                if (extName.ToLower().Equals(".xls")) // 97-2003版本
                {
                    wb = new HSSFWorkbook(ms);
                }

                else
                {
                    wb = new XSSFWorkbook(ms); // 2007以上版本
                }
                ISheet sheet = wb.GetSheetAt(0);
                //总行数（0开始）
                int totalRow = sheet.LastRowNum;
                // 总列数（1开始）
                int totalColumn = sheet.GetRow(0).LastCellNum;
                List<TCell> clist = new List<TCell>();
                for (int i = 1; i <= totalRow; i++)
                {
                    IRow row = sheet.GetRow(i);
                    //名称
                    string? Name ="";
                    if (row.GetCell(0)?.CellType == CellType.String)
                    {
                        Name = row.GetCell(0)?.StringCellValue;
                    }
                    else
                    {
                        Name = row.GetCell(0)?.NumericCellValue.ToString();
                    }
                    //编码
                    string? Code = row.GetCell(1)?.StringCellValue;
                    //巷道Id
                    string? roid = "";
                    if (row.GetCell(2)?.CellType == CellType.String)
                    {
                        roid = row.GetCell(2)?.StringCellValue;
                    }
                    else
                    {
                        roid = row.GetCell(2)?.NumericCellValue.ToString();
                    }
                    //货架Id
                    string? shid = "";
                    if (row.GetCell(3)?.CellType == CellType.String)
                    {
                        shid = row.GetCell(3)?.StringCellValue;
                    }
                    else
                    {
                        shid = row.GetCell(3)?.NumericCellValue.ToString();
                    }
                    string? shcode = row.GetCell(4)?.StringCellValue;
                    string? shname = row.GetCell(5)?.StringCellValue;
                    string? lineNo = "";
                    if (row.GetCell(6)?.CellType == CellType.String)
                    {
                        lineNo = row.GetCell(6)?.StringCellValue;
                    }
                    else
                    {
                        lineNo = row.GetCell(6)?.NumericCellValue.ToString();
                    }
                    string? layerNo = "";
                    if (row.GetCell(8)?.CellType == CellType.String)
                    {
                        layerNo = row.GetCell(8)?.StringCellValue;
                    }
                    else
                    {
                        layerNo = row.GetCell(8)?.NumericCellValue.ToString();
                    }
                    string? columnNo = "";
                    if (row.GetCell(7)?.CellType == CellType.String)
                    {
                        columnNo = row.GetCell(7)?.StringCellValue;
                    }
                    else
                    {
                        columnNo = row.GetCell(7)?.NumericCellValue.ToString();
                    }
                    string? depthIndex = "";
                    if (row.GetCell(9)?.CellType == CellType.String)
                    {
                        depthIndex = row.GetCell(9)?.StringCellValue;
                    }
                    else
                    {
                        depthIndex = row.GetCell(9)?.NumericCellValue.ToString();
                    }
                    int? IsMaxDepth= row.GetCell(10)?.StringCellValue == "是" ? 1 : 0;

                    var customer = new TCell
                    {
                        Name = Name,
                        CellType = 1,
                        Code = Code,
                        WhId = 2,
                        WhCode = "A01",
                        WhName = "中煤科院仓库",
                        AreaId = 3,
                        AreaCode = "002",
                        AreaName= "中煤科院库区",
                        RoutewayId = Convert.ToInt32(roid),
                        ShelfId =Convert.ToInt32(shid),
                        ShelfCode=Code,
                        ShelfName=shname,
                        Status=1,
                        LineNo=lineNo == null?0:Convert.ToInt32(lineNo),
                        LayerNo=layerNo == null ? 0 : Convert.ToInt32(layerNo),
                        ColumnNo=columnNo == null ? 0 : Convert.ToInt32(columnNo),
                        DepthIndex= depthIndex == null ? 0 : Convert.ToInt32(depthIndex),
                        IsMaxDepth=IsMaxDepth==1?true:false,
                        Erpcode="",
                        BusinessType=0,
                        IsLock=false,
                        FullStatus=0,
                        LogicalPartCode= "TongYongFQ",
                        LogicalPartName= "通用分区",
                        HeightType=1,
                        CreateUserId = uid,
                        CreateUserName = uname,
                        CreateDate = DateTime.Now,
                    };
                    clist.Add(customer);
                }
                if (clist.Count <= 0)
                {
                    //message = "文件信息为空或别写字段为空！";
                    return Ok(BaseResult.Result(false, "导入失败！" + message, "500"));
                }
                bool result = TCellRepository.AddCellRange(clist);
                wb.Close();
                if (result)
                {
                    return Ok(BaseResult.Result(true, "导入成功！" + message, "200"));
                }
                return Ok(BaseResult.Result(false, "导入失败！", "500"));
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 查询仓位信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult GetCellMaterial()
        {
            var list = TCellRepository.GetCellMaterial();
            if (list != null)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200", 0));
            }
            return Ok(BaseResult.Result(null, "查询成功！", "200", 0));
        }

        /// <summary>
        /// 根据托盘码查询物料信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult GetCellInvenMaterial(string palletcode)
        {
            var list = TCellRepository.GetCellInvenMaterial(palletcode);
            if (list != null)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200", 0));
            }
            return Ok(BaseResult.Result(null, "查询成功！", "200", 0));
        }


        /// <summary>
        /// 仓位统计
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult GetCellCount()
        {
            var list = TCellRepository.GetCellCount();
            if (list != null)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200", 0));
            }
            return Ok(BaseResult.Result(null, "查询成功！", "200", 0));
        }

        /// <summary>
        /// 上架单日统计
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult GetPutawayorderCount()
        {
            var list = TCellRepository.GetPutawayorderCount();
            if (list != null)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200", 0));
            }
            return Ok(BaseResult.Result(null, "查询成功！", "200", 0));
        }

        /// <summary>
        /// 上架单月统计
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult GetPutawayorderMonthCount()
        {
            var list = TCellRepository.GetPutawayorderMonthCount();
            if (list != null)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200", 0));
            }
            return Ok(BaseResult.Result(null, "查询成功！", "200", 0));
        }
    }
}
